package com.kk.controller;

import com.kk.model.User;
import com.kk.service.UserService;
import com.kk.util.request.Reqbody;
import com.kk.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by huang on 2018/8/13.
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/getAllUser")
    public Result getAllUser(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize) {
        Page<User> userPage = userService.findUserNoCriteria(pageIndex, pageSize);
//        List<User> userList = userService.getAllUser();
        return Result.success(userPage);
    }

    @GetMapping("/findUserByCondition")
    public Result findUserByCondition(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam String condition) {
//        Page<User> result = userService.findUserByCondition(pageIndex, pageSize, condition);
//        return Result.success(result);
        return null;
    }

    @GetMapping("/findUserByConditionTest")
    public Result findUserByConditionTest(Reqbody reqbody) {
//        reqbody.setExample(JSONUtil.parse(reqbody.getExample(), User.class));
        Page<User> result = userService.findUserByCondition(reqbody);
        return Result.success(result);
    }
}
